package part2_Basic_Thread_Synchronization.demo1;

import java.util.Scanner;


class Processor extends Thread{
	
	private volatile boolean running=true; // volatile is important , 
	// volatile logic : volatile variable cant be cached in thread , so if the variable is 
	// volatile and it was changed in other thread than current  , the current thread immediateli get the new value =)
	 
	@Override
	public void run() {
		
		while(running){
			System.out.println("hello");
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	public void shutdown(){
		this.running=false;
	}
}




public class App {

	
	public static void main(String[] args) {
		Processor proc1=new Processor();
		
		proc1.start();
		
		
		System.out.println("Press return to stop...");
		Scanner scanner=new Scanner(System.in);
		scanner.nextLine();
		
		proc1.shutdown();
		
		
	}

}
